/*
 * Copyright (c) 2020. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package cn.afterturn.easypoi.word.entity.handleWordEntity;

import cn.afterturn.easypoi.word.entity.bookmark.CellEntityVO;
import cn.afterturn.easypoi.word.entity.bookmark.WordEntityVO;

import java.util.Iterator;

public class HandleWordCellNull {
    public WordEntityVO handle(WordEntityVO wordEntityVO){
       /* wordEntityVO.getTableEntityVOS().forEach(tableEntity -> {
            if(tableEntity==null){
                System.out.println("表为null\r\n");
            }
            else {
                if(tableEntity.getRowEntityVOS()==null){
                    System.out.println("行为null\r\n");
                    tableEntity.getRowEntityVOS().forEach(rowEntity -> {
                        if(rowEntity.getCellEntityVOS()==null)
                        System.out.println("Cell为null\r\n");
                        else {
                            rowEntity.getCellEntityVOS().forEach(cellEntity -> {
                                if(cellEntity.getParagraphEntityVOS()==null){
                                    System.out.println("Para为null\r\n");
                                }else {
                                    cellEntity.getParagraphEntityVOS().forEach(paragraphEntity -> {
                                       if(paragraphEntity.getBookMarkEntityVOS()==null)
                                           System.out.println("Bookmark为null\r\n");
                                    });
                                }
                            });
                        }
                    });
                }
            }

        });*/


      /* wordEntityVO.getParagraphEntityVOS().forEach(paragraphEntity -> {
           Iterator<ParagraphEntityVO> iterator=wordEntityVO.getParagraphEntityVOS().iterator();
           while (iterator.hasNext()){
               paragraphEntity=iterator.next();
               if(paragraphEntity.getBookMarkEntityVOS()==null){
                   iterator.remove();
               }
           }
       });*/
        wordEntityVO.getTableEntityVOS().forEach(tableEntity -> {
            tableEntity.getRowEntityVOS().forEach(rowEntity -> {
                Iterator<CellEntityVO> iterator =rowEntity.getCellEntityVOS().iterator();
                while (iterator.hasNext()){
                    CellEntityVO cellEntityVO =iterator.next();
                    if(cellEntityVO.getParagraphEntityVOS()==null)
                        iterator.remove();
                }
                rowEntity.getCellEntityVOS().forEach(cellEntityVO -> {
                    if(cellEntityVO.getParagraphEntityVOS()==null){
                        rowEntity.getCellEntityVOS().remove(cellEntityVO);
                    }
                });
            });
        });

        return wordEntityVO;
    }
}